//package com.shwread.android.qysw.adapter;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import logic.bean.OrderFoodListBean;
//import logic.bean.OrderTakeoutBean;
//import logic.bean.OrderTakeoutTableBean;
//import logic.constants.Const;
//import logic.constants.DefaultConsts;
//import logic.util.ImageLoaderUtil;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.Paint;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.ViewGroup;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.LinearLayout.LayoutParams;
//import android.widget.TextView;
//
//import com.shwread.android.qysw10000133.R;
//import com.shwread.android.qysw.activity.OMFoodDetailActivity;
//import com.shwread.android.qysw.activity.OrderTakeoutActivity;
//import com.shwread.android.ui.widget.takeout.SectionedBaseAdapter;
//
//
//public class OrderTakeoutRightListAdapter
//        extends
//        SectionedBaseAdapter
//{
//	private List<OrderTakeoutBean>      leftList = new ArrayList<OrderTakeoutBean>();
//	private Context                     mContext;
//	private OrderTakeoutActivity        baseActivity;
//	private List<OrderTakeoutTableBean> rightBeans;
//
//	public OrderTakeoutRightListAdapter(Context context) {
//		this.mContext = context;
//		rightBeans = OrderTakeoutActivity.orderDao.getRightBeans();
//	}
//
//	public List<OrderTakeoutTableBean> getRightBeans() {
//		return rightBeans;
//	}
//
//	public void setRightBeans() {
//		rightBeans = OrderTakeoutActivity.orderDao.getRightBeans();
//		notifyDataSetChanged();
//	}
//
//	public void setActivity(OrderTakeoutActivity activity) {
//		baseActivity = activity;
//	}
//
//	public void setData(List<OrderTakeoutBean> leftList) {
//		this.leftList = leftList;
//		//		initRightData();
//		notifyDataSetChanged();
//	}
//
//	//	private void initRightData() {
//	//		if (rightList.size() > 0)
//	//		{
//	//			rightList.clear();
//	//		}
//	//		for (int i = 0; i < leftList.size(); i++)
//	//		{
//	//			rightList.put(i, leftList.get(i).getFoodList());
//	//		}
//	//	}
//
//	@Override
//	public Object getItem(int section, int position) {
//		return leftList.get(section).getFoodList().get(position);
//	}
//
//	@Override
//	public long getItemId(int section, int position) {
//		return position;
//	}
//
//	@Override
//	public int getSectionCount() {
//		return leftList.size();
//	}
//
//	@Override
//	public int getCountForSection(int section) {
//		return leftList.get(section).getFoodList().size();
//	}
//
//	@Override
//	public View getItemView(final int section, final int position, View convertView, ViewGroup parent) {
//		final OrderFoodListBean rightBean = leftList.get(section).getFoodList().get(position);
//		final OrderTakeoutBean leftBean = leftList.get(section);
//		final long rightBeanId = rightBean.getFoodId();
//		final long leftBeanId = leftBean.getDishesSortDto().getSortId();
//		convertView = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.order_takeout_right_list_item_view, null);
//		ImageView ivUrl = (ImageView) convertView.findViewById(R.id.order_takeout_right_item_url);
//		TextView tvName = (TextView) convertView.findViewById(R.id.order_takeout_right_item_name);
//		TextView tvSale = (TextView) convertView.findViewById(R.id.order_takeout_right_list_item_sale);
//		TextView tvJian = (TextView) convertView.findViewById(R.id.order_takeout_right_list_item_jian);
//		TextView tvPrice = (TextView) convertView.findViewById(R.id.order_takeout_right_list_item_price);
//		TextView tvYuanPrice = (TextView) convertView.findViewById(R.id.order_takeout_right_list_item_yuan_price);
//		LinearLayout llLadu = (LinearLayout) convertView.findViewById(R.id.order_takeout_right_item_ladu_ll);
//		final ImageView tvJia = (ImageView) convertView.findViewById(R.id.order_takeout_right_list_item_jia);
//		final LinearLayout llJia = (LinearLayout) convertView.findViewById(R.id.order_takeout_right_list_item_jia_ll);
//		ImageView ivJia = (ImageView) convertView.findViewById(R.id.order_takeout_right_list_item_jia_iv);
//		ImageView ivMinus = (ImageView) convertView.findViewById(R.id.order_takeout_right_list_item_jia_minus);
//		final TextView tvJiaTxt = (TextView) convertView.findViewById(R.id.order_takeout_right_list_item_jia_txt);
//		ImageLoaderUtil.loadWebUrl(rightBean.getPicUrl(), ivUrl, ImageLoaderUtil.getOptions(R.drawable.atlas_default_img));
//		if (rightBean.getPeppery_grade() > 0)
//		{
//			for (int i = 0; i < rightBean.getPeppery_grade(); i++)
//			{
//				ImageView iv = new ImageView(mContext);
//				LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//				lp.gravity = Gravity.CENTER_VERTICAL;
//				iv.setImageResource(R.drawable.order_takeout_right_iv_ladu);
//				llLadu.addView(iv);
//			}
//		}
//		else llLadu.setVisibility(View.GONE);
//		if (rightBeans != null && rightBeans.size() > 0)
//		{
//			for (int i = 0; i < rightBeans.size(); i++)
//			{
//				if (Integer.parseInt(rightBeans.get(i).getSortId()) == rightBean.getSortId() && rightBean.getFoodId() == Integer.parseInt(rightBeans.get(i).getFoodId()))
//				{
//					if (Integer.parseInt(rightBeans.get(i).getNum()) > 0)
//					{
//						llJia.setVisibility(View.VISIBLE);
//						tvJia.setVisibility(View.GONE);
//						tvJiaTxt.setText(rightBeans.get(i).getNum() + "");
//						//						baseActivity.selectFoodListBeans.add(rightBean);
//					}
//					else
//					{
//						llJia.setVisibility(View.GONE);
//						tvJia.setVisibility(View.VISIBLE);
//					}
//				}
//			}
//		}
//		else
//		{
//			llJia.setVisibility(View.GONE);
//			tvJia.setVisibility(View.VISIBLE);
//		}
//		//		if (bean.getSelectNum() > 0)
//		//		{
//		//			llJia.setVisibility(View.VISIBLE);
//		//			tvJia.setVisibility(View.GONE);
//		//			tvJiaTxt.setText(bean.getSelectNum() + "");
//		//		}
//		//		else
//		//		{
//		//			llJia.setVisibility(View.GONE);
//		//			tvJia.setVisibility(View.VISIBLE);
//		//		}
//		tvName.setText(rightBean.getFoodName());
//		tvSale.setText(rightBean.getSellNum() + "");
//		tvJian.setText(rightBean.getRecommendNum() + "");
//		if (rightBean.getHasActivity().equals("y"))
//		{
//			tvYuanPrice.setVisibility(View.VISIBLE);
//			tvYuanPrice.setText("¥" + (double) rightBean.getPrice() / 100);
//			tvYuanPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
//			tvPrice.setText("¥" + (double) rightBean.getActivityPrice() / 100);
//		}
//		else
//		{
//			tvYuanPrice.setVisibility(View.GONE);
//			tvPrice.setText("¥" + (double) rightBean.getPrice() / 100);
//		}
//		tvJia.setOnClickListener(new OnClickListener()
//		{
//			@Override
//			public void onClick(View arg0) {
//				tvJia.setVisibility(View.GONE);
//				llJia.setVisibility(View.VISIBLE);
//				insertBean(leftBean, rightBean, 1);
//				rightBean.setBuyNum(1);
//				baseActivity.addSelectFoodList(rightBean);
//				baseActivity.getUIHandler().sendEmptyMessage(0);
//			}
//		});
//		ivJia.setOnClickListener(new OnClickListener()
//		{
//			@Override
//			public void onClick(View arg0) {
//				int count = Integer.parseInt(tvJiaTxt.getText().toString());
//				tvJiaTxt.setText(++count + "");
//				//				leftList.get(section).setSelectNum(leftList.get(section).getSelectNum() + 1);
//				rightBean.setBuyNum(count);
//				insertBean(leftBean, rightBean, count);
//				baseActivity.addSelectFoodList(rightBean);
//				baseActivity.getUIHandler().sendEmptyMessage(0);
//			}
//		});
//		ivMinus.setOnClickListener(new OnClickListener()
//		{
//
//			@Override
//			public void onClick(View arg0) {
//				int count = Integer.parseInt(tvJiaTxt.getText().toString());
//				if (count > 1)
//				{
//					tvJiaTxt.setText(--count + "");
//				}
//				else
//				{
//					count--;
//					llJia.setVisibility(View.GONE);
//					tvJia.setVisibility(View.VISIBLE);
//				}
//				if (count > 0)
//				{
//					baseActivity.addSelectFoodList(rightBean);
//					insertBean(leftBean, rightBean, count);
//				}
//				else
//				{
//					OrderTakeoutActivity.selectFoodListBeans.remove(rightBean);
//					deleteBean(leftBean.getDishesSortDto().getSortId(), rightBean.getFoodId());
//				}
//				rightBean.setBuyNum(count);
//				//				leftList.get(section).setSelectNum(leftList.get(section).getSelectNum() - 1);
//				baseActivity.getUIHandler().sendEmptyMessage(0);
//
//			}
//		});
//		ivUrl.setOnClickListener(new OnClickListener()
//		{
//			@Override
//			public void onClick(View arg0) {
//				Intent detailIntent = new Intent(mContext, OMFoodDetailActivity.class);
//				detailIntent.putExtra("foodId", rightBean.getFoodId());
//				detailIntent.putExtra("sortId", rightBean.getSortId());
//				detailIntent.putExtra(DefaultConsts.FROM_TYPE, 1);
//				baseActivity.startActivityForResult(detailIntent, 100);
//			}
//		});
//		return convertView;
//	}
//
//	@Override
//	public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
//		LinearLayout layout = null;
//		if (convertView == null)
//		{
//			LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//			layout = (LinearLayout) inflator.inflate(R.layout.order_takeout_right_list_item_head_view, null);
//		}
//		else
//		{
//			layout = (LinearLayout) convertView;
//		}
//		layout.setClickable(false);
//		((TextView) layout.findViewById(R.id.textItem)).setText(leftList.get(section).getDishesSortDto().getName());
//		return layout;
//	}
//
//	class RightViewHolder
//	{
//		ImageView    ivUrl;
//		TextView     tvName;
//		TextView     tvSale;
//		TextView     tvJian;
//		TextView     tvPrice;
//		LinearLayout llLadu;
//		ImageView    tvJia;
//		LinearLayout llJia;
//		ImageView    ivJia;
//		ImageView    ivMinus;
//		TextView     tvJiaTxt;
//	}
//
//	private void insertBean(OrderTakeoutBean leftBean, OrderFoodListBean rightBean, int count) {
//		OrderTakeoutTableBean tableBean = new OrderTakeoutTableBean();
//		tableBean.setAccount(Const.phone_number);
//		tableBean.setSortId(String.valueOf(leftBean.getDishesSortDto().getSortId()));
//		tableBean.setFoodId(String.valueOf(rightBean.getFoodId()));
//		if (rightBean.getHasActivity().equals("y")) tableBean.setPrice(String.valueOf(rightBean.getActivityPrice() / 100));
//		else tableBean.setPrice(String.valueOf(rightBean.getPrice() / 100));
//		tableBean.setNum(count + "");
//		OrderTakeoutActivity.orderDao.addOrderTableBean(tableBean);
//	}
//
//	public void deleteBean(long leftBeanId, long rightBeanId) {
//		OrderTakeoutActivity.orderDao.deleteOrderTakeoutById(Const.phone_number, leftBeanId + "", rightBeanId + "");
//	}
//}
